<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Example: Basic DataTable</title>
    <link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
    <link rel="stylesheet" href="../assets/css/main.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <script src="../../build/yui/yui-min.js"></script>
</head>
<body>

<div id="doc">
    <h1>Example: Basic DataTable</h1>

    

    <div class="yui3-g">
        <div id="main" class="yui3-u">
            <div class="content"><style scoped>
/* custom styles for this example */
.dt-example {margin:1em;}

/* css to counter global site css */
.dt-example th {text-transform:none;}
.dt-example table {width:auto;}
.dt-example caption {display:table-caption;}
</style>

<div class="intro">
    <p>The DataTable widget displays data in a tabular format. Use plugins and extensions to add features and functionality to the <code>Y.DataTable.Base</code> class.</p>
</div>

<div class="example yui3-skin-sam">
    <div id="simple" class="yui3-skin-sam dt-example"></div>

<div id="labels" class="yui3-skin-sam dt-example"></div>

<script type="text/javascript">
YUI().use("datatable-base", function (Y) {
    var simpleCols = ["id","name","price"],
    simpleData = [
        {id:"ga_3475", name:"gadget", price:"$6.99"},
        {id:"sp_9980", name:"sprocket", price:"$3.75"},
        {id:"wi_0650", name:"widget", price:"$4.25"}
    ],
    labeledCols = [
        {key:"mfr_parts_database_id", label:"Mfr Part ID", abbr:"ID"},
        {key:"mfr_parts_database_name", label:"Mfr Part Name", abbr:"Name"},
        {key:"mfr_parts_database_price", label:"Wholesale Price", abbr:"Price"}
    ],
    labeledData = [
        {mfr_parts_database_id:"ga_3475", mfr_parts_database_name:"gadget", mfr_parts_database_price:"$6.99"},
        {mfr_parts_database_id:"sp_9980", mfr_parts_database_name:"sprocket", mfr_parts_database_price:"$3.75"},
        {mfr_parts_database_id:"wi_0650", mfr_parts_database_name:"widget", mfr_parts_database_price:"$4.25"}
    ],

    dt1 = new Y.DataTable.Base({columnset:simpleCols, recordset:simpleData, summary:"Price sheet for inventory parts", caption:"Example table with simple columns"}).render("#simple"),
    dt2 = new Y.DataTable.Base({columnset:labeledCols, recordset:labeledData, summary:"Price sheet for inventory parts", caption:"These columns have labels and abbrs"}).render("#labels");
});
</script>

</div>

<h2>Simple DataTable Use Cases</h2>

<pre class="code prettyprint">&lt;div id=&quot;example&quot; class=&quot;yui3-skin-sam&quot;&gt;&lt;&#x2F;div&gt;</pre>



<p>A basic table can be rendered into a given container by passing in a simple array of columns and an array of data objects into the constructor. As long as the columns map directly to the keys of the data objects, the table will be generated automatically from the data provided.</p>

<pre class="code prettyprint">YUI().use(&quot;datatable-base&quot;, function(Y) {
    var cols = [&quot;id&quot;,&quot;name&quot;,&quot;price&quot;],
    data = [
        {id:&quot;ga-3475&quot;, name:&quot;gadget&quot;, price:&quot;$6.99&quot;},
        {id:&quot;sp-9980&quot;, name:&quot;sprocket&quot;, price:&quot;$3.75&quot;},
        {id:&quot;wi-0650&quot;, name:&quot;widget&quot;, price:&quot;$4.25&quot;}
    ],
    dt = new Y.DataTable.Base({
        columnset: cols,
        recordset: data,
        summary: &quot;Price sheet for inventory parts&quot;,
        caption: &quot;Example table with simple columns&quot;
    }).render(&quot;#example&quot;);
});</pre>


<p>Your column definitions may be an array of object literals in order to support any number of configurations that are supported by the <code>Y.Column</code> class. For instance, you may wish to define a <code>label</code> that will be displayed in each column header. Use the <code>key</code> property to define where data for the column will be coming from.</p>

<pre class="code prettyprint">YUI().use(&quot;datatable-base&quot;, function(Y) {
    var cols = [
        { key: &quot;mfr_parts_database_id&quot;, label: &quot;Mfr Part ID&quot;, abbr: &quot;ID&quot;},
        { key: &quot;mfr_parts_database_name&quot;, label: &quot;Mfr Part Name&quot;, abbr: &quot;Name&quot;},
        { key: &quot;mfr_parts_database_price&quot;, label: &quot;Wholesale Price&quot;, abbr: &quot;Price&quot;}
    ],
    data = [
        { mfr_parts_database_id: &quot;ga_3475&quot;, mfr_parts_database_name: &quot;gadget&quot;, mfr_parts_database_price: &quot;$6.99&quot;},
        { mfr_parts_database_id: &quot;sp_9980&quot;, mfr_parts_database_name: &quot;sprocket&quot;, mfr_parts_database_price: &quot;$3.75&quot;},
        { mfr_parts_database_id: &quot;wi_0650&quot;, mfr_parts_database_name: &quot;widget&quot;, mfr_parts_database_price: &quot;$4.25&quot;}
    ],
    dt = new Y.DataTable.Base({
        columnset: cols,
        recordset: data,
        summary: &quot;Price sheet for inventory parts&quot;,
        caption: &quot;These columns have labels and abbrs&quot;
    }).render(&quot;#example&quot;);
});</pre>

</div>
        </div>

        <div id="sidebar" class="yui3-u">
            

            
                <div class="sidebox">
                    <div class="hd">
                        <h2 class="no-toc">Examples</h2>
                    </div>

                    <div class="bd">
                        <ul class="examples">
                            
                                
                                    <li data-description="This example illustrates simple DataTable use cases.">
                                        <a href="datatable-basic.html">Basic DataTable</a>
                                    </li>
                                
                            
                                
                                    <li data-description="DataTable loaded with JSON data from a remote webservice via DataSource.Get">
                                        <a href="datatable-dsget.html">DataTable + DataSource.Get + JSON Data</a>
                                    </li>
                                
                            
                                
                                    <li data-description="DataTable loaded with XML data from a remote webservice via DataSource.IO.">
                                        <a href="datatable-dsio.html">DataTable + DataSource.IO + XML Data</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Custom format data for display.">
                                        <a href="datatable-formatting.html">Formatting Row Data for Display</a>
                                    </li>
                                
                            
                                
                                    <li data-description="DataTable with nested column headers.">
                                        <a href="datatable-nestedcols.html">Nested Column Headers</a>
                                    </li>
                                
                            
                                
                                    <li data-description="DataTable with column sorting.">
                                        <a href="datatable-sort.html">Column Sorting</a>
                                    </li>
                                
                            
                                
                                    <li data-description="DataTable with vertical and/or horizontal scrolling rows.">
                                        <a href="datatable-scroll.html">Scrolling DataTable</a>
                                    </li>
                                
                            
                                
                            
                        </ul>
                    </div>
                </div>
            

            
                <div class="sidebox">
                    <div class="hd">
                        <h2 class="no-toc">Examples That Use This Component</h2>
                    </div>

                    <div class="bd">
                        <ul class="examples">
                            
                                
                            
                                
                            
                                
                            
                                
                            
                                
                            
                                
                            
                                
                            
                                
                                    <li data-description="Shows how to instantiate multiple Panel instances, and use nested modality to interact with a Datatable.">
                                        <a href="../panel/panel-form.html">Creating a modal form</a>
                                    </li>
                                
                            
                        </ul>
                    </div>
                </div>
            
        </div>
    </div>
</div>

<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>

</body>
</html>
